package com.hctg.forced2sleep.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;

import com.hctg.forced2sleep.R;

public class TitleBar extends LinearLayout {

    public ImageView ivBack, ivMore;

    public TextView tvTitle;

    public TextView tvRight;
    public TextView tvRight2;

    public TitleBar(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        setOrientation(HORIZONTAL);
        setGravity(Gravity.CENTER);
        LayoutInflater.from(context).inflate(R.layout.title_bar, this, true);
        ivBack = findViewById(R.id.iv_back);
        this.ivMore = findViewById(R.id.iv_more);
        this.tvTitle = findViewById(R.id.tv_title);
        this.tvRight = findViewById(R.id.tv_right);
        this.tvRight2 = findViewById(R.id.tv_right2);
    }

    public void setTitleLeft() {
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tvTitle.getLayoutParams();
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        tvTitle.setLayoutParams(layoutParams);
    }

    public void setIvMore(@DrawableRes int resId, OnClickListener onClickListener) {
        ivMore.setImageResource(resId);
        ivMore.setVisibility(View.VISIBLE);
        ivMore.setOnClickListener(onClickListener);
    }

    public void setTvRight(String str, OnClickListener onClickListener) {
        this.ivMore.setVisibility(View.GONE);
        this.tvRight.setVisibility(View.VISIBLE);
        this.tvRight.setVisibility(View.VISIBLE);
        this.tvRight.setText(str);
        this.tvRight.setOnClickListener(onClickListener);
    }

    public void setTvRight2(String str, OnClickListener onClickListener) {
        tvRight2.setVisibility(View.VISIBLE);
        tvRight2.setText(str);
        tvRight2.setOnClickListener(onClickListener);
    }

    public void setTitle(String str) {
        this.tvTitle.setText(str);
    }
}
